package com.hcrazy.manchester.app.jdbc;

import java.util.ArrayList;
import java.util.List;

import com.hcrazy.manchester.app.pojo.ForumRule;

public class ForumRuleDAO extends BaseDAO<ForumRule>{

	public void updateForumRule(List<ForumRule> rules) throws Exception {
		String sql = "update him_forum_rule set ruleValue=?,disabled=? where ruleType = ?";
		List<Object[]> list = new ArrayList<Object[]>();
		if(null != rules && !rules.isEmpty()){
			for(ForumRule rule:rules){
				Object[] objs = new Object[]{rule.getRuleValue(),rule.getDisabled(),rule.getRuleType()};
				list.add(objs);
			}
			getJdbcTemplate().batchUpdate(sql, list);
		}
		
	}
	
	public List<ForumRule> listAllRules() throws Exception{
		String sql = "select * from him_forum_rule order by ruleType";
		return getList(sql, ForumRule.class);
	}
	
	public ForumRule getById(int ruleType) throws Exception{
		String sql = "select * from him_forum_rule where ruleType = ?";
		return this.getJavaBean(sql, ForumRule.class, ruleType);
	}
	
	public void delForumRule(int ruleType) throws Exception{
		String sql = "delete from him_forum_rule where ruleType = ?";
		this.commonUpdate(sql, ruleType);
	}
	
}
